package com.ruoyi.web.controller.wb;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.wb.domain.WbContractUser;
import com.ruoyi.wb.domain.WbMaintainCompany;
import com.ruoyi.wb.service.IWbContractUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 合同用户关联Controller
 * 
 * @author ruoyi
 * @date 2024-10-25
 */
@RestController
@RequestMapping("/wb/contarctUser")
public class WbContractUserController extends BaseController
{
    @Autowired
    private IWbContractUserService wbContractUserService;

    /**
     * 查询合同用户关联列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WbContractUser wbContractUser)
    {
        startPage();
        List<WbContractUser> list = wbContractUserService.selectWbContractUserList(wbContractUser);
        return getDataTable(list);
    }

    /**
     * 导出合同用户关联列表
     */
    @Log(title = "合同用户关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WbContractUser wbContractUser)
    {
        List<WbContractUser> list = wbContractUserService.selectWbContractUserList(wbContractUser);
        ExcelUtil<WbContractUser> util = new ExcelUtil<WbContractUser>(WbContractUser.class);
        util.exportExcel(response, list, "合同用户关联数据");
    }

    /**
     * 获取合同用户关联详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wbContractUserService.selectWbContractUserById(id));
    }

    /**
     * 新增合同用户关联
     */
    @Log(title = "合同用户关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WbContractUser wbContractUser)
    {
        return toAjax(wbContractUserService.insertWbContractUser(wbContractUser));
    }

    /**
     * 修改合同用户关联
     */
    @Log(title = "合同用户关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WbContractUser wbContractUser)
    {
        return toAjax(wbContractUserService.updateWbContractUser(wbContractUser));
    }

    /**
     * 删除合同用户关联
     */
    @Log(title = "合同用户关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wbContractUserService.deleteWbContractUserByIds(ids));
    }


    /**
     * 批量新增合同用户关联
     */
    @Log(title = "批量新增合同用户关联", businessType = BusinessType.INSERT)
    @PostMapping("/addList")
    public AjaxResult addList(@RequestBody List<WbContractUser> wbContractUsers)
    {
        return toAjax(wbContractUserService.insertWbContractUserList(wbContractUsers));
    }

    /**
     * 查询用户合作伙伴
     */

    @Log(title = "查询用户合作伙伴", businessType = BusinessType.INSERT)
    @GetMapping("/partner")
    public TableDataInfo selectPartner()
    {
        List<WbMaintainCompany>  wbMaintainCompanies=wbContractUserService.selectPartner();

        return getDataTable(wbMaintainCompanies);
    }

}
